package com.jdd.modules.form.util;

import com.jdd.modules.form.entity.FormParkTotalInfo;

import java.text.SimpleDateFormat;
import java.util.Collections;
import java.util.Date;
import java.util.List;

/**
 * @author jdd
 * 检查是否有未查到的数据
 */
public class FormParkTotalInfoListUtil {
    public List<FormParkTotalInfo> listItemNullCheck(List<FormParkTotalInfo> list, int correctSize, String endTime, String parkCode) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        try {
            if (list.size() < correctSize) {
                for (int i = 0; i < correctSize; i++) {
                    Date endDate = simpleDateFormat.parse(endTime);
                    Date correctDate = new Date(endDate.getTime() - 1000L * 60 * 60 * 24 * i);
                    if (list.size() <= i) {
                        FormParkTotalInfo formParkTotalInfo = new FormParkTotalInfo();
                        formParkTotalInfo.setParkCode(parkCode);
                        formParkTotalInfo.setOutCarNumber(0);
                        formParkTotalInfo.setEnterCarNumber(0);
                        formParkTotalInfo.setIncome(0);
                        formParkTotalInfo.setPayTypeOne(0);
                        formParkTotalInfo.setPayTypeTwo(0);
                        formParkTotalInfo.setPayTypeThree(0);
                        formParkTotalInfo.setTime(simpleDateFormat.format(correctDate));
                        list.add(i, formParkTotalInfo);
                    } else {
                        if (!list.get(i).getTime().equals(simpleDateFormat.format(correctDate))) {
                            FormParkTotalInfo formParkTotalInfo = new FormParkTotalInfo();
                            formParkTotalInfo.setParkCode(parkCode);
                            formParkTotalInfo.setOutCarNumber(0);
                            formParkTotalInfo.setEnterCarNumber(0);
                            formParkTotalInfo.setIncome(0);
                            formParkTotalInfo.setPayTypeOne(0);
                            formParkTotalInfo.setPayTypeTwo(0);
                            formParkTotalInfo.setPayTypeThree(0);
                            formParkTotalInfo.setTime(simpleDateFormat.format(correctDate));
                            list.add(i, formParkTotalInfo);
                        }
                    }

                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        Collections.reverse(list);
        return list;
    }
}
